package servlet;

import dao.NoteDao;
import dao.RemarkDao;
import entity.Remark;
import entity.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/content.show")
public class ServletContent extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("进入文章内容展示和评论展示");
        NoteDao noteDao=new NoteDao();
        RemarkDao remarkDao=new RemarkDao();

        int noteid=Integer.parseInt(req.getParameter("noteid"));
        String username=ServletController.globaluser;
        Users users=new Users();
        users.setUsername(username);

        //修改浏览次数让其加一
        try {
            noteDao.updateNotereadnum(noteid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        //返回有关文章的信息和评论
        try {
            req.setAttribute("note",noteDao.selectNote(noteid));
            req.setAttribute("remarks",remarkDao.findNote_Remark(noteid));
            req.setAttribute("users",users);
            req.setAttribute("noteid",noteid);
            req.getRequestDispatcher("info.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
